package com.hecore.lagou.work.sort;

import com.hecore.lagou.speak.entity.SpeakBean;
import com.hecore.lagou.work.entity.SortNumBean;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: hecore
 * @Date: 2020/10/18 23:46
 * @Description: 排序数字Mapper
 *      第一个Key-v 偏移量&文本内容
 *      第二个Key-v 显示为 <Key-null>格式即可.
 */

public class SortNumMapper extends Mapper<LongWritable, Text, SortNumBean, NullWritable> {

    /**
     *
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    int sortKey=0;

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 1 获取⼀⾏
        int num=Integer.parseInt(value.toString());
        SortNumBean sortNumBean = new SortNumBean();
        sortKey=++sortKey;
        IntWritable v=new IntWritable(sortKey);
        sortNumBean.setSortKey(sortKey);
        sortNumBean.setNum(num);
        context.write(sortNumBean,NullWritable.get());
    }
}
